'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  /* new */
  /* 😎-------------- */

  async index() {
    const { ctx } = this;
    // test the page render:
    // await ctx.render("index");

    if (this.ctx.session.user) {
      await ctx.render("index");
    } else {
      ctx.redirect("/login");
    }
  }
  async login() {
    await this.ctx.render("login");
  }
  async logout() {
    this.ctx.session.user = '';
    this.ctx.redirect("/login");
  }
  async doLogin() {
    // this.logger.debug(`test logger module to dbug😎`);
    // console.log(this);
    // console.log(this.ctx);
    console.log(` 😂check ctx.request object`);
    // console.log(this.ctx.request);
    // console.log(this.ctx.request.body);
    console.log(`😂😂test by naive`);
    let username = this.ctx.request.body.username;
    let password = this.ctx.request.body.password;
    if (username == "x" && password == "x") {
      this.ctx.session.user = username;
      this.ctx.redirect("/");

    } else {
      this.ctx.redirect("/login");
    }
  }
  /*  */
  async testGetGril() {
    const ctx = this.ctx;
    let id = ctx.query.id;
    const res = await ctx.service.jspang.getGirl(id);
    ctx.body = res;
  }
  /* old */
  async index_old() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
    // test the middleware :counter:
    console.log(ctx.session.counter);

  }
}

module.exports = HomeController;
